package com.example.drzhang.oengldemo.render;

/**
 * Created by drzhang on 2018/1/10.
 */

public class MatrixHelper {

    /**
     * 创建透视矩阵
     * @param m
     * @param yFovInDegrees
     * @param aspect
     * @param n
     * @param f
     */
    public static void perspectiveM(float[] m, int yFovInDegrees, float aspect, float n, float f) {


        float angelInRadians = (float) (yFovInDegrees * Math.PI / 180);
        float a = (float) (1.0 / Math.tan(angelInRadians/2.0));

        m[0] = a / aspect;
        m[1] = 0.0f;
        m[2] = 0.0f;
        m[3] = 0.0f;

        m[4] = 0.0f;
        m[5] = a;
        m[6] = 0.0f;
        m[7] = 0.0f;

        m[8] = 0.0f;
        m[9] = 0.0f;
        m[10] = -((f + n) / (f - n));
        m[11] = -1.0f;

        m[12] = 0.0f;
        m[13] = 0.0f;
        m[14] = -((2f * f * n) / (f - n));
        m[15] = 0.0f;
    }

}
